package com.ytrsoft.config;

import jakarta.annotation.PostConstruct;
import jakarta.persistence.EntityManager;
import org.hibernate.Session;
import org.springframework.context.annotation.Configuration;
import org.springframework.transaction.annotation.Transactional;

@Configuration
public class HibernateFilterConfig {

    private final EntityManager entityManager;

    public  HibernateFilterConfig(EntityManager entityManager) {
        this.entityManager = entityManager;
    }

    @PostConstruct
    @Transactional
    public void enableDeletedFilter() {
        Session session = entityManager.unwrap(Session.class);
        session.enableFilter("deletedFilter").setParameter("isDeleted", false);
    }
}
